//
//  SGTransmissionOfLove.m
//  MomHelp
//
//  Created by xuguoyong on 16/8/22.
//  Copyright © 2016年 hudongkeji. All rights reserved.
//

#import "SGTransmissionOfLove.h"
#import "SGTotalLoveValue.h"
#import "iCarousel.h"
#import "SGLoveValueCarView.h"




@interface SGTransmissionOfLove() <iCarouselDelegate,iCarouselDataSource>
{
    //头部显示爱心值的View
    SGTotalLoveValue *_headerView;
    
   iCarousel *_pageView;
}


@end


@implementation SGTransmissionOfLove

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = @"爱心传递";
    //头部的爱心值
    [self setUpTotalLoveVulue];
    [self setUpPageView];

    
}
/**
 *  添加头部爱心值View
 */
- (void)setUpTotalLoveVulue
{
    _headerView = [[SGTotalLoveValue alloc]init];
    [self.view addSubview:_headerView];
    _headerView.sd_layout.leftEqualToView(self.view).rightEqualToView(self.view).heightIs(44).topEqualToView(self.view);
    
   
}

/**
 *  设置翻页
 */
- (void)setUpPageView
{
    
 
    
    _pageView = [[iCarousel alloc] initWithFrame:self.view.bounds];
    
    [self.view addSubview:_pageView];
    _pageView.sd_layout.topSpaceToView(_headerView,16.5).bottomSpaceToView(self.view,50).rightEqualToView(self.view).leftEqualToView(self.view);
    [_pageView updateLayout];
    SGLog(@"%@===%@",NSStringFromCGRect(_pageView.frame),NSStringFromCGRect(self.view.frame));
    _pageView.backgroundColor = [UIColor clearColor];
    [self.view setNeedsLayout];
    [self.view setNeedsDisplay];
    _pageView.delegate = self;
    _pageView.clipsToBounds = YES;
    _pageView.dataSource = self;
    
    _pageView.type = iCarouselTypeLinear;
 
    _pageView.bounceDistance = 0.55f;
    _pageView.pagingEnabled = YES;
    _pageView.bounces = YES;
    [_pageView scrollToItemAtIndex:20 animated:NO];
    
   
}


- (NSInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
    return 15;
}



- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view

{
    
    UIView *cardView = view;
    
    
    
    if ( !cardView )
        
    {
        
        cardView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, (d_screen_width/1.30f), carousel.height)];
       
        cardView.layer.cornerRadius = 5.0f;
        cardView.layer.masksToBounds = YES;
//        self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, cardView.width, cardView.height) style:UITableViewStylePlain];
//        [cardView addSubview:self.tableView];
//        
//        self.tableView.backgroundColor = viewAndTableViewBackgroundColor;
//        self.tableView.separatorColor = viewAndTableViewBackgroundColor;
//        self.tableView.delegate = self;
//        self.tableView.dataSource = self;
    }
    
    
    
    return cardView;
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 100;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
    }
    cell.textLabel.text = [NSString stringWithFormat:@"测试%ld",indexPath.row];
    return cell;
    
}

- (CGFloat)carousel:(iCarousel *)carousel itemAlphaForOffset:(CGFloat)offset
{
    //set opacity based on distance from camera
    return 1.0f - fminf(fmaxf(offset, 0.0f), 1.0f);
}


- (CATransform3D)carousel:(iCarousel *)_carousel itemTransformForOffset:(CGFloat)offset baseTransform:(CATransform3D)transform
{
    //implement 'flip3D' style carousel
    transform = CATransform3DRotate(transform, M_PI / 8.0f, 0.0f, 1.0f, 0.0f);
    return CATransform3DTranslate(transform, 0.0f, 0.0f, offset * _pageView.itemWidth);
}

- (BOOL)carouselShouldWrap:(iCarousel *)carousel
{
    return YES;
}

- (CGFloat)carousel:(iCarousel *)carousel valueForOption:(iCarouselOption)option withDefault:(CGFloat)value
{
    
    switch (option) {
        case iCarouselOptionSpacing:
        {
        return 1.1f;
        }
            break;
        case iCarouselOptionWrap:
        {
           
        }
            break;
        default:
            break;
    }
   
    return value;
}
@end
